<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  


    <ui:composition template="layout.xhtml">-->

        <ui:define name="corpo">
            <h:form id="transferirImovel" acceptcharset="utf-8"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexImovel.xhtml')}" value="Imóvel" update="@form" immediate="true"/> >
                    <p:commandLink  value="Transferir Imóvel" update="@form" immediate="true"/>
                </div>
            <p:messages id="msg"/>
               <p:panel header="Transferir Imovel">                        
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Imóvel"/></legend>
                        <h:panelGrid  columns="4" border="0" styleClass="textAlignRightBold">  

                            <h:outputLabel value="Origem do Imóvel:" />
                            <h:outputText value="#{managerTransfencia.operacaoTransf.tipo}" />

                            <h:outputLabel value="" />
                            <h:outputLabel value="" />

                            <h:outputLabel value="Registro: " /> 
                            <h:outputText value="#{managerTransfencia.imovelTransf.registro}" />

                            <h:outputLabel value="Data:" for="data"/>                       
                            <h:outputText value="#{managerTransfencia.imovelTransf.dataCadastro}" >
                                <f:convertDateTime pattern="dd/MM/yyyy"/>
                            </h:outputText>

                        </h:panelGrid>

                    </fieldset>   
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Valor"/></legend>
                        <h:outputLabel value="Valor do Imóvel: " for="valor"/>
                        <p:inputText value="#{managerTransfencia.transferenciaImovel.valor}" id="valor"
                                     onchange="jQuery(this).autoNumeric({aSep: '.', aDec: ','} );">
                            <f:convertNumber pattern="#,###,##0.00"/>
                        </p:inputText>
                    </fieldset>
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Titulo"/></legend>
                        <h:panelGrid columns="2" id="panelGridTitulo" styleClass="textAlignRight" columnClasses="textAlignRight">
                            <h:outputLabel value="Titulo: " for="titulo"/>                                    

                            <p:autoComplete id="titulo" value="#{managerTransfencia.transferenciaImovel.titulo}" completeMethod="#{managerTitulo.completeTitulo}"  
                                            var="p" itemLabel="#{p.nome}" itemValue="#{p}" converter="tituloConverter" forceSelection="true" converterMessage="Erro, verifique o titulo" minQueryLength="3" dropdown="true" required="true" requiredMessage="O campo 'Forma Titulo' é obrigato"> 
                                <p:ajax event="itemSelect" listener="#{managerTransfencia.handleSelect}"/>                                        

                            </p:autoComplete>

                            <h:outputLabel value="Forma titulo: " for="formaTitulo"/>
                            <p:inputTextarea value="#{managerTransfencia.transferenciaImovel.formaTitulo}" id="formaTitulo" cols="100" rows="4" autoResize="true" />

                        </h:panelGrid>
                    </fieldset>

                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Adquirente"/></legend>

                        <p:commandButton value="Adicionar" icon="ui-icon-circle-plus" style="float:right; margin-left: 5px" onclick="buscaAdquirente.show()" immediate="true"/>
                        <br/> 
                        <br/>
                        <h:panelGrid columns="1" id="lstColAdquirente" width="100%" styleClass="textAlignRight" columnClasses="textAlignRight">             
                            <p:dataTable id="lstadquirente" rows="5"  var="adquirente" value="#{managerTransfencia.transferenciaImovel.adquirente}" emptyMessage="Adicione Adquirente">  
                                <f:facet name="header">  
                                    Adquirentes
                                </f:facet>
                                <p:column style="width:16px">  
                                    <p:rowToggler />  
                                </p:column>
                                <p:column id="modelHeader">  
                                    <f:facet name="header">  
                                        <h:outputText value="Nome" />
                                    </f:facet>  
                                    <h:outputText value="#{adquirente.nome}" />  
                                </p:column>  
                                <p:column>  
                                    <f:facet name="header">  
                                        <h:outputText value="Documento" />  
                                    </f:facet>  
                                    <h:outputText value="#{adquirente.cpf eq null ? adquirente.cnpj : adquirente.cpf}" />  
                                </p:column> 
                                <p:column style="width:50px;">  
                                    <f:facet name="header">  
                                        <h:outputText value="Remover" />  
                                    </f:facet>
                                    <p:commandButton icon="ui-icon-circle-close" actionListener="#{managerTransfencia.removeListAdquirenteTransf(adquirente)}" update=":transferirImovel:lstColAdquirente" immediate="true" ajax="true"/>

                                </p:column>
                                <p:rowExpansion >  
                                    <h:outputText value="Nome: " style="font-weight:bold;" />  
                                    <h:outputText id="nome" value="#{adquirente.nome}" />  
                                    <h:outputText value=" - CPF: " style="font-weight:bold;"/>  
                                    <h:outputText id="year" value="#{adquirente.cpf}" />  
                                    <br/>
                                </p:rowExpansion>  
                            </p:dataTable>  
                        </h:panelGrid>
                    </fieldset>
                    <br/>
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Transmitente"/></legend>

                        <h:panelGrid columns="1" id="lstColTransmitente" width="100%" styleClass="textAlignRight" columnClasses="textAlignRight">             
                            <p:dataTable id="lsttransmitente" rows="5"  var="transmitente" value="#{managerTransfencia.transferenciaImovel.transmitente}" emptyMessage="Adicione Adquirente">  
                                <f:facet name="header">  
                                    Transmitentes
                                </f:facet>
                                <p:column style="width:16px">  
                                    <p:rowToggler />  
                                </p:column>
                                <p:column id="modelHeader">  
                                    <f:facet name="header">  
                                        <h:outputText value="Nome" />
                                    </f:facet>  
                                    <h:outputText value="#{transmitente.nome}" />  
                                </p:column>  
                                <p:column>  
                                    <f:facet name="header">  
                                        <h:outputText value="#{transmitente.cpf eq null ? 'CNPJ' : 'CPF'}" />  
                                    </f:facet>  
                                    <h:outputText value="#{transmitente.cpf eq null ? transmitente.cnpj : transmitente.cpf}" />  
                                </p:column> 
                                <p:rowExpansion >  
                                    <h:outputText value="Nome: " style="font-weight:bold;" />  
                                    <h:outputText id="nomeTable" value="#{transmitente.nome}" />  
                                    <h:outputText value=" - CPF: " style="font-weight:bold;"/>  
                                    <h:outputText id="cpfTable" value="#{transmitente.cpf}" />  
                                    <br/>
                                    <h:outputText value="Endereco: " style="font-weight:bold;"/>  
                                     <h:outputText value="#{transmitente.endereco.tipo_logradouro.toString().toLowerCase()} #{transmitente.endereco.logradouro.toString().toLowerCase()}
                                            #{transmitente.endereco.numero}, Bairro #{transmitente.endereco.bairro} #{transmitente.endereco.cep eq '' ? '': ', CEP'} #{transmitente.endereco.cep}" />  
                                    
                                    <br/>
                                </p:rowExpansion>  
                            </p:dataTable>  
                        </h:panelGrid>
                    </fieldset>
                    <fieldset class="ui-fieldset" id="fieldAnexo" >
                        <legend>Anexos</legend>
                        <p:fileUpload fileUploadListener="#{managerTransfencia.handleFileUpload}"  
                                      mode="advanced"  
                                      update="msg"   
                                      multiple="true" 
                                      uploadLabel="Anexar"
                                      label="Carregar"
                                      cancelLabel="Cancelar"
                                      allowTypes="/(\.|\/)(gif|jpe?g|png|pdf|tif|doc|docx|ppt|pptx|xls|xlsx)$/"
                                      invalidFileMessage="Arquivo não suportado, favor verifique o tipo do arquivo."
                                      invalidSizeMessage="Tamanho do arquivo é inválido."
                                      sizeLimit="10000000"
                                      />  

                    </fieldset>
                    <br/>
                    <div class="buttonAction">
                        <p:commandButton id="upa" icon="ui-icon-disk" value="Transferir" 
                                         actionListener="#{managerTransfencia.transfImovel()}" 
                                         update="@form" process="@form"/>
                        <p:commandButton id="limpar" icon="ui-icon-close" value="Limpar" type="reset" />  
                        <p:ajaxStatus style="width:16px;height:16px;" id="ajaxStatusPanel">  
                            <f:facet name="start">  
                                <h:graphicImage value="/media/img/loading.gif" />  
                            </f:facet>  

                            <f:facet name="complete">  
                                <h:outputText value="" />  
                            </f:facet>  
                        </p:ajaxStatus>

                    </div>
                </p:panel>
            </h:form>
            <h:form id="formdialog"  acceptcharset="utf-8">
                <p:growl showDetail="true"  id="msgDialog" />
                <p:dialog id="dialogAdquirente" header="Adicione Adquirente" modal="true" widgetVar="buscaAdquirente" resizable="false"  
                          showEffect="clip" hideEffect="fold" style="top:50%;">
                    <p:ajax event="close" update=":transferirImovel:lstadquirente" listener="#{managerPessoa.clear()}"/> 
                    <p:selectOneRadio id="controleAdquirenteSelectOne" value="#{managerPessoa.controleAdquirente}"
                                      label="Selecione um item">
                        <f:selectItem itemLabel="Pessoa Fisica"  itemValue="#{true}"/>
                        <f:selectItem itemLabel="Pessoa Juridica"  itemValue="#{false}"/>
                        <p:ajax  update="filtroPessoaAdquirenteCPF, controleAdquirenteSelectOne, colAdquirente" event="change" />
                    </p:selectOneRadio>
                    <h:panelGrid columns="2" id="colAdquirente" cellpadding="10px" styleClass="textAlignRight" columnClasses="textAlignRight">             
                        <h:outputLabel value="Nome:  " for="filtroPessoaAdquirenteNome"/> 
                        <p:inputText value="#{managerPessoa.pessoa.nome}" 
                                     id="filtroPessoaAdquirenteNome" maxlength="60" size="70" />

                        <h:outputLabel value="Documento: " for="filtroPessoaAdquirenteCPF"/> 
                        <p:row>
                            <p:inputText value="#{managerPessoa.controleAdquirente ? managerPessoa.pessoa.cpf : managerPessoa.pessoa.cnpj}" 
                                         id="filtroPessoaAdquirenteCPF" maxlength="60" />                        
                            <p:commandButton value="Buscar" style="margin-left: 5px" process="colAdquirente" actionListener="#{managerPessoa.buscar()}" update="dataTable, msgDialog" />
                        </p:row>
                    </h:panelGrid>                    
                    <p:dataTable var="item" id="dataTable" value="#{managerPessoa.listpessoa}" 
                                 rowKey="#{item.id}"
                                 selection="#{managerPessoa.pessoaaux}"
                                 selectionMode="single"
                                 paginator="true" rows="10"
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 emptyMessage="Nenhum registro encontrado"
                                 >  
                        <p:ajax event="rowSelect" listener="#{managerTransfencia.selecionaAdquirenteTransf(managerPessoa.selecionaPessoa())}" update=":transferirImovel:lstadquirente"/>
                        <p:column  id="pessoaNome" headerText="Nome">
                            #{item.nome}
                        </p:column>
                        <p:column  id="pessoaCPF" headerText="#{item.cpf eq null ? 'CNPJ' : 'CPF'}">
                            #{item.cpf eq null ? item.cnpj : item.cpf}
                        </p:column>
                    </p:dataTable>
                </p:dialog>
            </h:form>
        </ui:define>
    </ui:composition>
</html>